/*
  Copyright 2009 Smart Enterprise Solution Corp.
  Email: contact@ses.vn - Website: http://www.ses.vn
  KimNgan Project.
*/
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Data.SqlClient;
using DOAN.DO;
/// <summary>
/// Summary description for BailamDAL
/// </summary>
namespace DOAN.DAL
{

    public class BailamDAL : BaseDAL
    {
        #region Private Variables

        #endregion

        #region Public Constructors
        public BailamDAL()
        {
            //
            // TODO: Add constructor logic here
            //

        }
        #endregion



        #region Public Methods
        public int Insert(BailamDO objBailamDO)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spBailam_Insert";
            SqlParameter Sqlparam;

            Sqlparam = new SqlParameter("@Madethi", SqlDbType.Int);
            Sqlparam.Value = objBailamDO.Madethi;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@Tongdiem", SqlDbType.Int);
            Sqlparam.Value = objBailamDO.Tongdiem;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@Ngaythi", SqlDbType.VarChar);
            Sqlparam.Value = objBailamDO.Ngaythi;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@Tentaikhoan", SqlDbType.VarChar);
            Sqlparam.Value = objBailamDO.Tentaikhoan;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@Traloi", SqlDbType.VarChar);
            Sqlparam.Value = objBailamDO.Traloi;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@ID", SqlDbType.Int);
            Sqlparam.Direction = ParameterDirection.ReturnValue;
            Sqlcomm.Parameters.Add(Sqlparam);


            int result = base.ExecuteNoneQuery(Sqlcomm);

            if (!Convert.IsDBNull(Sqlcomm.Parameters["@ID"]))
                result = Convert.ToInt32(Sqlcomm.Parameters["@ID"].Value);

            return result;
        }

        public int Update(BailamDO objBailamDO)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spBailam_UpdateByPK";
            SqlParameter Sqlparam;

            Sqlparam = new SqlParameter("@Mabailam", SqlDbType.Int);
            Sqlparam.Value = objBailamDO.Mabailam;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@Madethi", SqlDbType.Int);
            Sqlparam.Value = objBailamDO.Madethi;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@Tongdiem", SqlDbType.Int);
            Sqlparam.Value = objBailamDO.Tongdiem;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@Ngaythi", SqlDbType.VarChar);
            Sqlparam.Value = objBailamDO.Ngaythi;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@Tentaikhoan", SqlDbType.VarChar);
            Sqlparam.Value = objBailamDO.Tentaikhoan;
            Sqlcomm.Parameters.Add(Sqlparam);



            Sqlparam = new SqlParameter("@ErrorCode", SqlDbType.Int);
            Sqlparam.Direction = ParameterDirection.ReturnValue;
            Sqlcomm.Parameters.Add(Sqlparam);

            int result = base.ExecuteNoneQuery(Sqlcomm);

            if (!Convert.IsDBNull(Sqlcomm.Parameters["@ErrorCode"]))
                result = Convert.ToInt32(Sqlcomm.Parameters["@ErrorCode"].Value);

            return result;


        }

        public int Delete(BailamDO objBailamDO)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spBailam_DeleteByPK";
            SqlParameter Sqlparam;


            Sqlparam = new SqlParameter("@Mabailam", SqlDbType.Int);
            Sqlparam.Value = objBailamDO.Mabailam;
            Sqlcomm.Parameters.Add(Sqlparam);



            int result = base.ExecuteNoneQuery(Sqlcomm);
            return result;
        }

        public int DeleteAll()
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spBailam_DeleteAll";

            int result = base.ExecuteNoneQuery(Sqlcomm);
            return result;
        }

        public DataTable GetByMonAndNgay(string mamon, string lop, string dat)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spBailam_GetByMonAndNgay2";
            SqlParameter Sqlparam;


            Sqlparam = new SqlParameter("@mamon", SqlDbType.VarChar);
            Sqlparam.Value = mamon;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@lop", SqlDbType.VarChar);
            Sqlparam.Value = lop;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@date", SqlDbType.VarChar);
            Sqlparam.Value = dat;
            Sqlcomm.Parameters.Add(Sqlparam);


            DataSet ds = base.GetDataSet(Sqlcomm);
            DataTable dt = new DataTable();
            if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                dt = ds.Tables[0];
            }
            return dt;
        }

        public BailamDO Select(BailamDO objBailamDO)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spBailam_GetByPK";
            SqlParameter Sqlparam;


            Sqlparam = new SqlParameter("@Mabailam", SqlDbType.Int);
            Sqlparam.Value = objBailamDO.Mabailam;
            Sqlcomm.Parameters.Add(Sqlparam);



            DataSet ds = base.GetDataSet(Sqlcomm);
            DataRow dr = null;
            if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                dr = ds.Tables[0].Rows[0];
                if (!Convert.IsDBNull(dr["Mabailam"]))
                    objBailamDO.Mabailam = Convert.ToInt32(dr["Mabailam"]);
                if (!Convert.IsDBNull(dr["Madethi"]))
                    objBailamDO.Madethi = Convert.ToInt32(dr["Madethi"]);
                if (!Convert.IsDBNull(dr["Tongdiem"]))
                    objBailamDO.Tongdiem = Convert.ToInt32(dr["Tongdiem"]);
                if (!Convert.IsDBNull(dr["Ngaythi"]))
                    objBailamDO.Ngaythi = Convert.ToString(dr["Ngaythi"]);
                if (!Convert.IsDBNull(dr["Tentaikhoan"]))
                    objBailamDO.Tentaikhoan = Convert.ToString(dr["Tentaikhoan"]);

            }
            return objBailamDO;
        }

        public ArrayList SelectAll1()
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spBailam_GetAll";

            DataSet ds = base.GetDataSet(Sqlcomm);
            DataTable dt = null;
            ArrayList arrBailamDO = new ArrayList();
            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];
                foreach (DataRow dr in dt.Rows)
                {
                    BailamDO objBailamDO = new BailamDO();
                    if (!Convert.IsDBNull(dr["Mabailam"]))
                        objBailamDO.Mabailam = Convert.ToInt32(dr["Mabailam"]);
                    if (!Convert.IsDBNull(dr["Madethi"]))
                        objBailamDO.Madethi = Convert.ToInt32(dr["Madethi"]);
                    if (!Convert.IsDBNull(dr["Tongdiem"]))
                        objBailamDO.Tongdiem = Convert.ToInt32(dr["Tongdiem"]);
                    if (!Convert.IsDBNull(dr["Ngaythi"]))
                        objBailamDO.Ngaythi = Convert.ToString(dr["Ngaythi"]);
                    if (!Convert.IsDBNull(dr["Tentaikhoan"]))
                        objBailamDO.Tentaikhoan = Convert.ToString(dr["Tentaikhoan"]);
                    arrBailamDO.Add(objBailamDO);
                }
            }
            return arrBailamDO;
        }

        public DataTable SelectAll()
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spBailam_GetAll";

            DataSet ds = base.GetDataSet(Sqlcomm);
            DataTable dt = null;

            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];

            }
            return dt;
        }


        #endregion

    }

}
